package com.aatrox.bhsypro.controller;

import com.aatrox.bhsypro.util.TencentYunVedioUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import static com.aatrox.bhsypro.util.TencentYunVedioUtil.*;


/**
 * @Author zhushaojie
 * @Date 2020/6/15 18:24
 */
@RestController
public class TestController {

    /**
     * 生成推流全路径地址
     *      * @param pushUrl 推流地址 头部
     *      * @param stream_id 直播码  调用该方法genLiveCode() 生成  
     *      * @param push_key 推流鉴权
     *      * @return
     *     
     */
    @RequestMapping(value = "/createPushUrl",method = RequestMethod.OPTIONS)
    public static String createPushUrl() {
        //过期时间 16进制的unix时间戳
        String txTime = to16Hex(addOneDay());
        // 填写自己的streamName
        String streamName="yilaoshi_1";
        StringBuffer sb = new StringBuffer();
        String pushUrlHead= TencentYunVedioUtil.pushUrl;
        // String stream_id = TencentYunVedioUtil.bizid();
        sb.append(pushUrlHead).append("?").append("txSecret=")
                .append(genSign(push_key, streamName,txTime)).append("&").append("txTime=")
                .append(txTime);
        return sb.toString();
    }


    /**
     *      * 生成拉流全路径地址
     *      * @param playUrlHead  拉流的头地址
     *      * @param stream_id  直播码  调用该方法genLiveCode() 生成  
     *      * @param play_key  拉流鉴权
     *      * @param end 如 .flv结尾
     *      * @return
     */
    @RequestMapping(value = "/createPlayUrl",method = RequestMethod.OPTIONS)
    public static String createPlayUrl() {
        //过期时间 16进制的unix时间戳

        String txTime = to16Hex(addOneDay());
        StringBuffer sb = new StringBuffer();
        //String stream_id = TencentYunVedioUtil.bizid();
        sb.append(playUrl_flv).append("?").append("txSecret=").append(pushSign(play_key, txTime))
                .append("&")
                .append("txTime=")
                .append(txTime);
        return sb.toString();
    }

}

